$TITLE ('RTX-51 TO KEIL C-51 INTERFACE')
$SYMBOLS
$NOXREF
$NOCOND
$NOMOD51
$NORB
$PAGELENGTH(80) PAGEWIDTH(110)
;************************************************************************
;*									*
;*    R T X - 5 1  :   RTX-51 TO KEIL C-51 INTERFACE                    *
;*                                                                      *
;*----------------------------------------------------------------------*
;*                                                                      *
;*    Filename     :   RTX2C51.A51                                      *
;*    Language     :   Keil A-51                                        *
;*    Dev. system  :   Keil uVision2                                    *
;*    Targetsystem :   Any system based upon 8051 up                    *
;*                                                                      *
;*    Purpose      :   This module holds all the data structures        *
;*                     for the coupling of RTX-51 with Keil C-51.       *
;*                     All data structures which may be manipulated     *
;*                     by Keil C-51 are defined in this module.         *
;*                     (the only exception is the definition of the     *
;*                     driver-tasks stack in the module RTXCONF).       *
;*                                                                      *
;*----------------------------------------------------------------------*
;* Rev. |  Released   | Programmer    | Comments                        *
;*----------------------------------------------------------------------*
;* 0.1  |  16.4.91    | Th. Fischler  | First Version                   *
;*      |  13.6.91    |               | First full functional Version   *
;* 5.00 |  20.10.1994 | E. Glatz      | Release 5.00                    *
;* 7.00 |  13.11.2001 | T. Mueller    | Release 7.00                    *
;************************************************************************
;*    Copyright 1991 .. 2001 METTLER  &  FUCHS  AG,  CH-8953 Dietikon   *
;************************************************************************

$INCLUDE (RTXIMASK.INC)

;*----------------------------------------------------------------------*
;*	I M P O R T S
;*----------------------------------------------------------------------*

$INCLUDE (RTXCONST.INC)


;        FROM RTXCONF
EXTRN    BIT   (?RTX_TFLAG)

;        FROM RTXDATA
EXTRN    DATA  (?RTX_ACT_LIFO_EL)
EXTRN    XDATA (?RTX_ISR_LIFO)
EXTRN    BIT   (?RTX_SYSCLK_ISR)
EXTRN    DATA  (?RTX_TMP0, ?RTX_TMP1, ?RTX_TMP2, ?RTX_TMP3)

;        FROM RTXCONF
; Processor specific interrupt enable masks
EXTRN    DATA  (?RTX_IE, ?RTX_IEN1, ?RTX_IEN2)


;*----------------------------------------------------------------------*
;*	E X P O R T S
;*----------------------------------------------------------------------*

;	 Variables for the task-context (used by BL51)
PUBLIC   ?RTX_TASKENTRY, ?RTX_REGBANK, ?RTX_PRIORITY
PUBLIC   ?RTX_TASKNUMBER, ?RTX_TASKCONTEXT

;        System-Constants
PUBLIC   ?RTX_EXTREGSIZE

;        Flags
PUBLIC   ?RTX_TS_DELAY, ?RTX_TS_REQ

;        Initial-Task-Descriptor Table
PUBLIC   ?RTX_TASKCONST

;        Table for external to internal task-number conversion
PUBLIC   ?RTX_USER_NUM_TABLE

;        Shows the interrupts used by ISR-Routines
PUBLIC   ?RTX_ISRDESCR

;        Taskswitching for Floating-Point Operations
PUBLIC   ?RTX_TASKSWITCHING


;*----------------------------------------------------------------------*
;*      S Y S T E M - C O N S T A N T S
;*----------------------------------------------------------------------*

;  Register-context area for each non-driver task in external RAM
;  Used the following way:
;  ACC,R7,R6,R5,R4,R3,R2,R1,R0,B,DPH,DPL,PSW,SP,CONTEXT_TYPE,P2,?RTX_PBP,BANK
?RTX_EXTREGSIZE      EQU   18

   
;*----------------------------------------------------------------------*
;*      BIT-VARIABLES FOR LONG- AND FLOAT OPERATIONS
;*----------------------------------------------------------------------*
;  Flags for the handling of Float-operations with round-robin
;  scheduling (see documentation)
;

?RTX?FLT_BITSEG   SEGMENT  BIT
                  RSEG  ?RTX?FLT_BITSEG

?RTX_TS_DELAY:    DBIT  1
?RTX_TS_REQ:      DBIT  1



;*----------------------------------------------------------------------*
;*	T A S K - D E S C R I P T O R S
;*----------------------------------------------------------------------*
;  Dummy-Segment for the Taskdescriptors, will be initialiced by BL-51
;

?RTX?TASKCONST?L  SEGMENT  CODE
                  RSEG ?RTX?TASKCONST?L

?RTX_TASKCONST:
?RTX_TASKENTRY:   DS 2
?RTX_REGBANK:     DS 1
?RTX_PRIORITY:    DS 1
?RTX_TASKNUMBER:  DS 1
?RTX_TASKCONTEXT: DS 2



;*----------------------------------------------------------------------*
;*      I S R - T A B L E
;*----------------------------------------------------------------------*
?RTX?ISRDESCR     SEGMENT  CODE
                  RSEG     ?RTX?ISRDESCR

?RTX_ISRDESCR:    DS NBR_OF_INT



;*----------------------------------------------------------------------*
;*	N O R M A L - T A S K - C O N T E X T	A R E A S
;*----------------------------------------------------------------------*
;  Dummy-Segment for the task-contexts. The Startaddress of each context
;  is included in the task-descriptor (?RTX?TASKCONTEXT)
;
?RTX?TASKCONTEXT?N   SEGMENT  XDATA INPAGE
		     RSEG     ?RTX?TASKCONTEXT?N

                     DS 1                       ; Dummy declaration


;*----------------------------------------------------------------------*
;*      F A S T - T A S K   R E E N T R A N T   S T A C K
;*----------------------------------------------------------------------*
?RTX?FTASKCONTEXT?U  SEGMENT  XDATA INPAGE
                     RSEG ?RTX?FTASKCONTEXT?U

                     DS 1                    ; Dummy declaration



;*----------------------------------------------------------------------*
;*      T A B L E   F O R   T H E   U S E R - N U M B E R S
;*----------------------------------------------------------------------*
;  Holds the references between external and internal
;  Task-Numbers. BL51 will multiplicate the segment-length with
;  ?RTX_MAXTASKN+1

?RTX?USER_NUM_TABLE?S  SEGMENT  XDATA INPAGE
                       RSEG     ?RTX?USER_NUM_TABLE?S

?RTX_USER_NUM_TABLE:   DS 1                     ; ?RTX_MAXTASKN+1 Byte



;*----------------------------------------------------------------------*
;*      CODE FOR TASKSWITCHING WITH FLOAT-OPERATIONS
;*----------------------------------------------------------------------*

?RTX?FLT_TASKSWITCHING?RTX2C51  SEGMENT  CODE
                                RSEG  ?RTX?FLT_TASKSWITCHING?RTX2C51

?RTX_TASKSWITCHING:
               CLR   ?RTX_TS_REQ
               GLOBAL_INT_DISABLE
               ; save the registers used by C-51
               MOV   ?RTX_TMP0, A
               MOV   ?RTX_TMP1, PSW
               MOV   ?RTX_TMP2, DPH
               MOV   ?RTX_TMP3, DPL
               ; Check if free place in LIFO
               MOV   A, ?RTX_ACT_LIFO_EL
               CLR   C
               SUBB  A, #ISR_LIFO_SIZE-1
               JC    LIFO_FREE
               MOV   A, ?RTX_TMP0
               MOV   PSW, ?RTX_TMP1
               MOV   DPH, ?RTX_TMP2
               MOV   DPL, ?RTX_TMP3
               GLOBAL_INT_ENABLE
               RET

LIFO_FREE:     MOV   A, ?RTX_ACT_LIFO_EL
               ADD   A, #LOW(?RTX_ISR_LIFO)
               MOV   DPL, A
               MOV   DPH, #HIGH(?RTX_ISR_LIFO)
               ; Setup LIFO-entry
               MOV   A, #REQ_ROUND_R_CMD
               MOVX  @DPTR, A                   ; store Command
               MOV   A, ?RTX_ACT_LIFO_EL
               ADD   A, #3
               MOV   ?RTX_ACT_LIFO_EL, A        ; ?RTX_ACT_LIFO_EL incremented

               ; Check if System-Clock-Handler is active
               JB    ?RTX_SYSCLK_ISR, CLK_ACT
               SETB  ?RTX_TFLAG                 ; activate overflow-INT
CLK_ACT:       MOV   A, ?RTX_TMP0
               MOV   PSW, ?RTX_TMP1
               MOV   DPH, ?RTX_TMP2
               MOV   DPL, ?RTX_TMP3
               GLOBAL_INT_ENABLE
               RET


;
;   END OF MODULE
;
	END
